<%@page contentType="text/html;charset=UTF-8" %><%@page import="java.util.LinkedList" %><%@page import="be.destin.util.Util" %><%@page import="be.destin.skos.core.SkosManager" %><%@page import="be.destin.skos.core.Concept" %><%@page import="be.destin.skos.core.Application" %><%@page import="be.destin.skos.html.SkosHtmlManager" %><%@page import="be.destin.skos.core.SchemeInterface" %><%@page import="be.destin.skos.view.SkosView" %><%@page import="be.destin.skos.view.SkosViewType" %><%@page import="be.destin.skos.view.ViewConcept" %><%@page import="be.destin.skos.view.SkosViewManager" %><%@page import="be.destin.memolog.UsageMode" %><%@page import="be.destin.memolog.UsageLogger" %><%@page import="be.destin.memo.Log" %><%@page import="be.destin.memo.TagDef" %><%@page import="be.destin.memo.Tagged" %><%@page import="be.destin.memolog.SessionMemoManager" %><%@page import="java.util.List" %><%@page import="java.util.LinkedHashSet" %><%@page import="java.util.LinkedHashMap" %><%
	SkosHtmlManager skosHtmlManager = SkosHtmlManager.getAskosiSessionInstance(request);
	SkosManager skosManager = skosHtmlManager.getSkosManager();
	String language = skosHtmlManager.getLanguage();
	SchemeInterface aScheme = skosManager.getApplications();
	aScheme = skosManager.getMetaScheme();
	LinkedList<ViewConcept> schemesConcepts = null;
	SkosView schemesView = null;
	if (aScheme != null) {
		SkosViewType viewType = SkosViewType.ALFA;
		schemesView = SkosViewManager.openView(skosHtmlManager,aScheme.getAbout(), viewType, language,false, null);
		schemesConcepts = SkosViewManager.getConcepts(schemesView);
	}
	SessionMemoManager smm = new SessionMemoManager(request);
	String currentBasket = smm.getBasketName();
%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jqueryui.css" />
	<!--link rel="stylesheet" href="css/redmond/jquery-ui-1.10.3.custom.min.css"/-->
    <script type="text/javascript">
    	var userBasket = '<%=Util.escapeJavaScript(currentBasket) %>';
    </script>
	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.23.custom.js"></script>
	<script src="js/jsuri-1.1.1.min.js"></script>
	<!-- link rel="stylesheet" href="http://jqueryui.com/demos/demos.css" -->
    <script type="text/javascript" src="js/binding-atom.js"></script>
    <script type="text/javascript" src="js/atomModel.js"></script>
    <script type="text/javascript" src="metadatajson.jsp"></script>
    <script type="text/javascript" src="js/underscore-1.1.7.js"></script>
    <script type="text/javascript" src="js/facetedsearch.js"></script>
	<link rel="stylesheet" href="css/glisp-feed.css"/>
	<link rel="stylesheet" href="css/askosi.css"/>
<%	
	String go = request.getParameter("button");
	String service = request.getParameter("service");
	String url = request.getParameter("url");		
	String collection = ((String)request.getParameter("collection"));
	if (collection != null) collection=collection.trim();
	if (collection == null || collection.isEmpty() || "-".equals(collection)) {
		collection = "";
	}
	String query = request.getParameter("query");
	if (query==null) {
		query = (String) pageContext.getSession().getAttribute("query");
		if (query==null) query="";
	}
	pageContext.getSession().setAttribute("query",query);
	if (go != null && (service == null || service.isEmpty() || (service.indexOf("scheme") >= 0))) {
			service = "scheme";
	}
%>
    <script type="text/javascript" src="js/glisp-feed.js"></script>
	<title><%=(service==null?"":(service+'='))%><%=query%>: GLISP Result Browse</title>
</head>
<body class="contentpage">
<div id="headerscrolling">
<%String pageID = "TOC";%><%@include file="basket.jnc"%>
	<%@include file="searchbox.jnc"%> 
</div>
<div id="content"><img src="image/carrevide.gif" height="100" border="0" alt="top margin"/><br style="clear:both"/>
<%
	   if (go != null) {
		   boolean closed = true;
	       if (!service.equals("*")) {
	    	   tableApps = new LinkedHashMap<String,Application>();
	    	   tableApps.put(service,((Application) skosManager.getApplications().getConcept(service)));
	    	   closed = false;
	       }
	       for (Application aVConcept: tableApps.values()) {
	    	   String atomURL = aVConcept.getAtomURL(); 
	    	   if (atomURL != null && !atomURL.isEmpty()) {
				%>
			    <div id="<%=aVConcept.getAbout()%>" class="mainResult lev0">
					<div id="feedLabel">Waiting for feed <%=aVConcept.getAbout()%>...</div>
			    	<div id="facets" class="yellow">Waiting for Facets...</div>
					<div id="bottom">Waiting for sort options...</div>
			      	<div id="results">Waiting for results...</div>
			    </div>
				<% if (atomURL != null && !atomURL.isEmpty()) {
						atomURL = atomURL.replace("{searchTerms}",query);
						atomURL = atomURL.replace("{/scheme}",(collection==""? "" : '/'+collection));
						atomURL = atomURL.replace("{scheme}",collection);%>
				    <script type="text/javascript">
				       	insertFeed("<%=atomURL%>",'<%=aVConcept.getAbout()%>',1,<%=closed?"true":"false"%>);
				    </script>
				<% }    
	    	 }
		   }
	   } else if (url != null) {
		   %><div id="URL" class="mainResult lev0">
				<div id="feedLabel">Waiting for feed <%=url%>...</div>
		    	<div id="facets" class="yellow">Waiting for Facets...</div>
				<div id="bottom">Waiting for sort options...</div>
		      	<div id="results">Waiting for results...</div>
		    </div>
			<% if (url != null && !url.isEmpty()) {
					url = url.replace("{searchTerms}",query);
					url = url.replace("{/scheme}",(collection==""? "" : '/'+collection));
					url = url.replace("{scheme}",collection);%>
			    <script type="text/javascript">
			       	insertFeed("<%=url%>",'URL',1);
			    </script> <%
			}
	   }
%>    <p><a href="javascript:dumpFeed()"><small><i>last data received</i></small></a></p>
<%--
	    <form action="glispbrowse.jsp" method="GET">
		<table border="0" cellspacing="4px" cellpadding="4px" class="ui-widget-header" style="border: solid black 1px;">
		<tr><th>Service:</th><td><select name="service"><% for (String anAbout: glispApps) { %><option value="<%=anAbout%>"><%Concept aConcept = appScheme.getConcept(anAbout);%><%=aConcept.getPrefLabel(language,false)%></option><% } %></select></td></tr>
		<tr><th>Query:</th><td><input name="query" value="<%=query%>" size="80"/></td></tr>
		<tr><th>ConceptScheme:</th><td><select name="collection"><option value='-'>(any)</option><% for (ViewConcept aVConcept: schemesConcepts) { %><option value="<%=aVConcept.getAbout()%>"<%if (collection.equals(aVConcept.getAbout())) {%> selected<%} %>><%=aVConcept.getPrefLabel()%></option><% } %></select></td></tr>
		<tr><th colspan="2"><input type="submit" name="button" value="GO"/></th></tr>
		</table>
		</form> --%>
</div>
<div id="breadcrumbs" class="popup_foreground_container">breadcrumbs</div>
<div id="paw"><a href="#" onclick="javascript:lastclicks();return false;"><img src="image/paw.png" border="0"/></a></div>
</body></html>
